package com.masterrabbit.mcslf.xxxjob;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.masterrabbit.mcslf.mapper.DailyFlowMapper;
import com.masterrabbit.mcslf.pojo.DailyFlow;
import com.masterrabbit.mcslf.service.DailyFlowService;
import com.masterrabbit.mcslf.utils.TimeUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.TimeUnit;


@Component("testTask")
public class TestJob  implements InitializingBean {


    @Autowired
    private DailyFlowMapper dailyFlowMapper;

    @Autowired
    DailyFlowService dailyFlowService;



//    添加每日流水

    @Override
    public void afterPropertiesSet() throws Exception {
//        System.out.println(this.dailyFlowMapper);
//        System.out.println(dailyFlowMapper);
//        System.out.println("检查今日流水是否存在");
////        TimeUtil.getcruntTime("YYYY-MM-dd")
//        QueryWrapper<DailyFlow> dailyFlowQueryWrapper = new QueryWrapper<>();
//        dailyFlowQueryWrapper.lambda().like(DailyFlow::getRecoedDate, TimeUtil.getcruntTime("YYYY-MM-dd"));
//        DailyFlow dailyFlowByTime = dailyFlowService.getOne(dailyFlowQueryWrapper);
//
//        if (dailyFlowByTime == null) {
//            System.out.println("创建今日流水");
////        一天后事件
//            DailyFlow dailyFlow = new DailyFlow();
//            dailyFlow.setRecoedDate(new Date());
//            dailyFlowMapper.insert(dailyFlow);
//            System.out.println("今日流水创建成功");
//        }
    }
    public void createDaily() throws ParseException {
        Long time = System.currentTimeMillis();
//        一天后事件
        DailyFlow dailyFlow = new DailyFlow();
        dailyFlow.setRecoedDate(new Date(time + TimeUnit.HOURS.toMillis(24)));
        dailyFlowMapper.insert(dailyFlow);
    }
}
